package com.sjq.db;

import java.sql.*;

public class Dbutil {
    public static String JDBC_DRIVER="com.mysql.jdbc.Driver";
    public static String JDBC_URL="jdbc.mysql.//127.0.0.1:3306/medical";
    public static String JDBC_USER="root";
    public static String JDBC_PASSWORD="123456";


    public Connection getConn()throws Exception{
        Connection conn=null;
        try {
            Class.forName(JDBC_DRIVER);
            conn= DriverManager.getConnection(JDBC_URL,JDBC_USER,JDBC_PASSWORD);
            return conn;
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }

    public void close(ResultSet rs, Statement stmt, Connection conn)throws SQLException {

        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
            throw e;
        }
    }
    public void close(Statement stmt,Connection conn)throws SQLException{
        close(null,stmt,conn);
    }

}
